import 'package:json_annotation/json_annotation.dart';

part 'ring_sport_detail.g.dart';

/// 运动明细数据模型
@JsonSerializable()
class RingSportDetail {
  /// 设备ID
  @JsonKey(name: 'deviceSn')
  final String deviceSn;

  /// 历史日期
  @JsonKey(name: 'historyDay')
  final String historyDay;

  /// 步数列表（逗号分隔的字符串）
  @JsonKey(name: 'stepsList')
  final String stepsList;

  const RingSportDetail({
    required this.deviceSn,
    required this.historyDay,
    required this.stepsList,
  });

  /// 从JSON创建实例
  factory RingSportDetail.fromJson(Map<String, dynamic> json) =>
      _$RingSportDetailFromJson(json);

  /// 转换为JSON
  Map<String, dynamic> toJson() => _$RingSportDetailToJson(this);

  /// 从步数数据创建运动明细
  factory RingSportDetail.fromStepsData({
    required String deviceSn,
    required String historyDay,
    required List<int> stepsList,
  }) {
    return RingSportDetail(
      deviceSn: deviceSn,
      historyDay: historyDay,
      stepsList: stepsList.join(','),
    );
  }

  @override
  String toString() {
    return 'RingSportDetail(deviceSn: $deviceSn, historyDay: $historyDay, stepsList: $stepsList)';
  }
}
